package com.company.admin.common.myException;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 赵成林
 * @date 2019/2/16 21:21
 * 全局异常处理器
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 系统异常
     * @param e
     * @return
     */
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public ExceptionVo exceptionHandler(Exception e){
        ExceptionVo vo = new ExceptionVo();
        vo.setCode(100);
        vo.setMessage("系统未知错误");
        e.printStackTrace();
        return vo;
    }

    /**
     * 业务逻辑异常
     * @param e
     * @return
     */
    @ResponseBody
    @ExceptionHandler(value = BizException.class)
    public ExceptionVo bizExceptionHandler(BizException e){
        ExceptionVo vo = new ExceptionVo();
        vo.setMessage(e.getMessage());
        vo.setCode(e.getCode());
        return vo;
    }
}
